package controller;


import service.CourseService;
import service.Impl.CourseServiceImpl;
import service.Impl.TeacherServiceImpl;
import service.TeacherService;
import servlet.BaseServlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/teacher")
public class TeacherController extends BaseServlet {

    private TeacherService teacherService = new TeacherServiceImpl();

    public void doInitModify(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {
        String teacher = teacherService.initModify(request, response);
        CourseService courseService = new CourseServiceImpl();
        String courses = courseService.getCourses(request, response);
        String jsonStr = "{'teacher':'" + teacher + "','courses':'" + courses + "'}";
        response.getWriter().write(jsonStr);
    }

    public void doModify(HttpServletRequest request,HttpServletResponse response) throws IOException {
        String code = teacherService.modify(request, response);
        response.getWriter().write(code);
    }

}